/**
 * FileName: AirCarDispatch
 * Author:   Leopold
 * Date:     2018/8/16 15:36
 * Description: 车辆调度
 * History:
 */
package cn.mcsys.myadmin.modules.air.web;

import cn.mcsys.myadmin.common.web.JsonResult;
import cn.mcsys.myadmin.modules.air.entity.AirCar;
import cn.mcsys.myadmin.modules.air.service.AirCarService;
import cn.mcsys.myadmin.modules.air.service.AirRidePointService;
import cn.mcsys.myadmin.modules.air.vo.AddCarVO;
import cn.mcsys.myadmin.modules.air.vo.AirRidePointVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "${adminPath}/air/carDispatch")
public class AirCarDispatchController {

    @Autowired
    private AirRidePointService airRidePointService;

    @Autowired
    private AirCarService airCarService;

    @RequestMapping(value = "index")
    public String index(Model model){
        Map points = airRidePointService.selectAllPoint();
        List<AirRidePointVO> rps = (List<AirRidePointVO>)points.get("rps");
        List<AirRidePointVO> ems = (List<AirRidePointVO>)points.get("ems");
        model.addAttribute("pointVO",rps);
        model.addAttribute("emsPointVO",ems);
        return "modules/air/airCarDispatch";
//        return JsonResult.success(points);
    }

    /**
     * 查询在转移框中选中的车辆
     * @param ids
     * @return
     */
    @RequestMapping(value = "getCheckOn")
    @ResponseBody
    public JsonResult getCheckOnCar(Long[] ids){
        List<AirCar> cars = airCarService.selectByIds(ids);
        return JsonResult.success(cars);
    }

    /**
     *  新增车辆框的
     * @param pointId
     * @return
     */
    @RequestMapping(value = "getPointCars")
    @ResponseBody
    public JsonResult getEmergencyCars(Long pointId){
        List<AirCar> cars = airCarService.getPointCars(pointId);
        List<AirCar> emergencyCar = airCarService.getEmergencyCar();
        AddCarVO addCarVO = new AddCarVO();
        addCarVO.setCars(cars);
        addCarVO.setEmergencyCars(emergencyCar);
        return JsonResult.success(addCarVO);
    }

    /**
     * 各个乘车点的车辆转移到一个乘车点中
     * @param carIds
     * @param pointId
     * @return
     */
    @RequestMapping(value = "moveCarUpdate")
    @ResponseBody
    public JsonResult moveCarUpdate(Long[] carIds,Long pointId){
        airRidePointService.moveCarUpdate(carIds,pointId);
        return JsonResult.success();
    }

    /**
     * 更新应急停车场和乘车点车辆
     * @param cars
     * @param emergencyCars
     * @param carPointId
     * @param emergencyPointId
     * @return
     */
    @RequestMapping(value = "addPointCarSave")
    @ResponseBody
    public JsonResult addPointCarSave(Long[] cars,Long[] emergencyCars,Long carPointId,Long emergencyPointId){
        airRidePointService.addPointCarSave(cars,emergencyCars,carPointId,emergencyPointId);
        return  JsonResult.success();
    }
}
